package com.aaa.bbb.mymaintain.api;


import com.aaa.bbb.common.http.ResponseResult;
import com.aaa.bbb.mymaintain.entity.Employee;
import com.aaa.bbb.mymaintain.entity.IssuesManager;
import com.aaa.bbb.mymaintain.form.AssignPersonForm;
import com.aaa.bbb.mymaintain.form.IssueEmployeeUpdateForm;
import com.aaa.bbb.mymaintain.form.IssuesEmployeeForm;
import com.aaa.bbb.mymaintain.form.IssuesManagerProblemForm;
import com.aaa.bbb.mymaintain.service.IssuesEmployeeSer;
import com.aaa.bbb.mymaintain.service.IssuesManagerSer;
import com.github.pagehelper.PageInfo;
import com.max.back.common.sercurity.anno.AuthIgrone;
import com.max.back.demo.entity.Bschool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author max
 * @since 2023-11-03
 */
@CrossOrigin
@RestController
@RequestMapping("/api/issues_manager")
public class IssuesManagerCtl {
    @Autowired
    private IssuesManagerSer ser;

    @PostMapping("/getproblem")
    public ResponseResult<PageInfo<Map<String, Object>>> getProblem(@RequestBody @Valid IssuesManagerProblemForm form) {
        PageInfo<Map<String, Object>> pager = ser.queryPagerByCond(
                "问题未审核",
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

    @PostMapping("/getfund")
    public ResponseResult<PageInfo<Map<String, Object>>> getFund(@RequestBody @Valid IssuesManagerProblemForm form) {
        PageInfo<Map<String, Object>> pager = ser.queryPagerByCond(
                "经费申请中",
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

    @PostMapping("/getrepair")
    public ResponseResult<PageInfo<Map<String, Object>>> getRepair(@RequestBody @Valid IssuesManagerProblemForm form) {
        PageInfo<Map<String, Object>> pager = ser.queryPagerByCond(
                "判定无法维修",
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

    @PostMapping("/updateproblem")
    public void updateProblem(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
       ser.updateIssueManager(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/updatefund")
    public void updateFund(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
        ser.updateFund1(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/assignperson")
    public void assignPerson(@RequestBody @Validated AssignPersonForm form) {
        ser.assignPerson1(form.getIssue_id(),form.getMaintenance_id());
    }

    @PostMapping("/updatepersist")
    public void updatePersist(@RequestBody @Validated({IssueEmployeeUpdateForm.Update.class}) IssueEmployeeUpdateForm form) {
        ser.updatePersist1(form.getIssue_id(),form.getState(),form.getReason());
    }

    @PostMapping("/getinformation")
    public ResponseResult<PageInfo<Map<String, Object>>> getInformation(@RequestBody @Valid IssuesManagerProblemForm form) {
        PageInfo<Map<String, Object>> pager = ser.queryPagerByParam(
                form.getName(),
                form.getGender(),
                form.getState(),
                form.getPageNum(),
                form.getPageSize()
        );
        return ResponseResult.getSuccessResult(pager);
    }

}

